package com.vichat.api.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.vichat.api.vo.LocationDataVO;
import com.vichat.common.util.NumberUtils;
import com.vichat.common.util.StringUtil;
import com.vichat.room.entity.RoomBasic;
import com.vichat.user.entity.UserBasic;
import com.vichat.user.entity.UserOrg;
import org.apache.commons.lang3.StringUtils;

public class CheckUtil {
    public static void checkAddUser(UserBasic user) throws Exception {
        if (NumberUtils.isNullOrZero(user.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (NumberUtils.isNullOrZero(user.getOrgId())) {
            throw new Exception("缺少参数orgId");
        }
        if (!StringUtils.isNotBlank(user.getTerminal())) {
            throw new Exception("缺少参数terminal");
        }
        if (!StringUtils.isNotBlank(user.getUserName())) {
            throw new Exception("缺少参数userName");
        }
    }
    public static void checkModUser(UserBasic user) throws Exception {
        if (NumberUtils.isNullOrZero(user.getUid())) {
            throw new Exception("缺少参数uid");
        }
        if (NumberUtils.isNullOrZero(user.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (!StringUtils.isNotBlank(user.getUserName())) {
            throw new Exception("缺少参数userName");
        }
    }
    public static void checkResetPasswd(UserBasic user) throws Exception {
        if (NumberUtils.isNullOrZero(user.getUid())) {
            throw new Exception("缺少参数uid");
        }
        if (NumberUtils.isNullOrZero(user.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (!StringUtils.isNotBlank(user.getPassword())) {
            throw new Exception("缺少参数password");
        }
    }
    public static void checkAcitivityUser(UserBasic user) throws Exception {
        if (NumberUtils.isNullOrZero(user.getUid())) {
            throw new Exception("缺少参数uid");
        }
        if (NumberUtils.isNullOrZero(user.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (user.getExpiredDate() == null) {
            throw new Exception("缺少参数expiredDate");
        }
        if (!StringUtils.isNotBlank(user.getUserName())) {
            throw new Exception("缺少参数userName");
        }
    }

    public static void checkAddRoom(RoomBasic roomBasic) throws Exception {
        if (NumberUtils.isNullOrZero(roomBasic.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (!StringUtils.isNotBlank(roomBasic.getName())) {
            throw new Exception("缺少参数name");
        }
    }

    public static void checkModRoom(RoomBasic roomBasic) throws Exception {
        if (NumberUtils.isNullOrZero(roomBasic.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (NumberUtils.isNullOrZero(roomBasic.getRid())) {
            throw new Exception("缺少参数rid");
        }
        if (!StringUtils.isNotBlank(roomBasic.getName())) {
            throw new Exception("缺少参数name");
        }
    }

    public static void checkGetLocationLog(LocationDataVO queryBean) throws Exception {
        if (NumberUtils.isNullOrZero(queryBean.getUid())) {
            throw new Exception("缺少参数uid");
        }
        if (queryBean.getQueryDate() == null) {
            throw new Exception("缺少参数queryDate");
        }
    }

    public static void checkGetLocationSwitch(JSONObject userJsonObj, JSONArray uidsJSONArray) throws Exception {
        if (uidsJSONArray == null || uidsJSONArray.size() == 0) {
            throw new Exception("缺少参数uids");
        }
        if (!userJsonObj.containsKey("locFlag")) {
            throw new Exception("缺少参数locFlag");
        }
        if (!userJsonObj.containsKey("locInterval")) {
            throw new Exception("缺少参数locInterval");
        }
    }

    public static void checkAddOrg(UserOrg org) throws Exception {
        if (NumberUtils.isNullOrZero(org.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (!StringUtils.isNotBlank(org.getOrgName())) {
            throw new Exception("缺少参数orgName");
        }
    }

    public static void checkModOrg(UserOrg org) throws Exception {
        if (NumberUtils.isNullOrZero(org.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (NumberUtils.isNullOrZero(org.getOrgId())) {
            throw new Exception("缺少参数orgId");
        }
        if (!StringUtils.isNotBlank(org.getOrgName())) {
            throw new Exception("缺少参数orgName");
        }
    }

    public static void checkDelOrg(UserOrg org) throws Exception {
        if (NumberUtils.isNullOrZero(org.getPartyId())) {
            throw new Exception("缺少参数partyId");
        }
        if (NumberUtils.isNullOrZero(org.getOrgId())) {
            throw new Exception("缺少参数orgId");
        }
    }
}
